/*
Action:通过操作mutation间接更新state的多个方法的对象
 */

// 注意要引入api接口函数
import {
  // reqAppInfo
} from '../api'
import {
  SET_CURURL,
  CHANGE_LOADINGVIS,
} from './mutation-types'
export default {


  // 异步获取商家商品列表
  async searchShops({ commit, state }, keyword) {
    const geohash = state.latitude + ',' + state.longitude
    const result = await reqSearchShop(geohash, keyword)
    if (result.code === 0) {
      const searchShops = result.data
      commit(RECEIVE_SEARCH_SHOPS, { searchShops })
    }
  },

  // 异步获取appInfo
  async getAppInfo({ commit, state }, callback) {
    const result = await reqAppInfo();
    if (result.code === 1) {
      const data = result.data;
      commit(GET_APPINFO, { data });
      callback && callback();
    }
  },

  // 保存当前要跳转的路由
  saveCurUrl({ commit, state }, { data }, callback) {
    commit(SET_CURURL, data)
  },
  // 切换loading的状态
  changeLoadingVis({ commit, state }, { data }, callback) {
    commit(CHANGE_LOADINGVIS, data)
  }
}
